import {createAction} from 'redux-actions';
import httpUtil from '../utils/HttpUtil';
import * as homeTypes from '../utils/type/HomeTypes';
import Url from '../utils/Constant';

function getBanner() {
    return dispatch => {
        httpUtil.get(Url.WApiBanner)
            .then(res => {
                dispatch(createAction(homeTypes.FETCH_HOME_BANNNER_DONE)(res.data))
            });
    }
}

function getArticles(page) {
    return dispatch => {
        dispatch(createAction(homeTypes.FETCH_HOME_ARTUICLE_DOING)(page===0));
        httpUtil.get(Url.WApiArticle0 + page + Url.WApiArticle1)
            .then(res => dispatch(createAction(homeTypes.FETCH_HOME_ARTUICLE_DONE)(res.data)))
            .catch(e => dispatch(createAction(homeTypes.FETCH_HOME_ARTUICLE_ERROR)(e)));
    }
}

export {
    getBanner,
    getArticles
}